import http from '@/utils/http'

const BASE_URL = '/testing/environment'

export interface EnvironmentResp {
  id: string
  projectId: string
  name: string
  protocol: string
  domain: string
  port: string
  description: string
  version: string
  status: string
  isDeleted: string
  createdBy: string
  updatedBy: string
  createdAt: string
  updatedAt: string
  createUserString: string
  updateUserString: string
}
export interface EnvironmentDetailResp {
  id: string
  projectId: string
  name: string
  protocol: string
  domain: string
  port: string
  description: string
  version: string
  status: string
  isDeleted: string
  createdBy: string
  updatedBy: string
  createdAt: string
  updatedAt: string
  createUserString: string
  updateUserString: string
}
export interface EnvironmentQuery {
  projectId: string
  name: string
  protocol: string
  domain: string
  port: string
  version: string
  createdBy: string
  sort: Array<string>
}
export interface EnvironmentPageQuery extends EnvironmentQuery, PageQuery {}

/** @desc 查询环境列表 */
export function listEnvironment(query: EnvironmentPageQuery) {
  return http.get<PageRes<EnvironmentResp[]>>(`${BASE_URL}`, query)
}

/** @desc 查询环境详情 */
export function getEnvironment(id: string) {
  return http.get<EnvironmentDetailResp>(`${BASE_URL}/${id}`)
}

/** @desc 新增环境 */
export function addEnvironment(data: any) {
  return http.post(`${BASE_URL}`, data)
}

/** @desc 修改环境 */
export function updateEnvironment(data: any, id: string) {
  return http.put(`${BASE_URL}/${id}`, data)
}

/** @desc 删除环境 */
export function deleteEnvironment(id: string) {
  return http.del(`${BASE_URL}/${id}`)
}

/** @desc 导出环境 */
export function exportEnvironment(query: EnvironmentQuery) {
  return http.download<any>(`${BASE_URL}/export`, query)
}
